class Homes::Show::SessionsController < ApplicationController
  def new
  end

  def create
    if Valleyer.authenticate(params[:session][:nick_name],params[:session][:password])
      session[:current_valleyer_id] = Valleyer.find_by_nick_name(params[:session][:nick_name]).id
      # remember me
      if params[:session][:remember_me] == 'yes'
        cookies[:valleyer_id] = {
          :value => current_valleyer_id.to_s,
          :expires => 10.years.from_now
        }
        cookies[:valleyer_security_key] = {
          :value => current_valleyer.security_key_in_cookies,
          :expires => 10.years.from_now
        }
      else
        clear_login_info_from_cookies
      end      
    else
      @login_failed = true
      clear_login_info_from_cookies
      
      render :action => :new
    end
  end

  def show
    
  end

  def destroy
    session[:current_valleyer_id] = nil
    clear_login_info_from_cookies
    redirect_to home_url(:default)
  end

  def authorize
      
  end

  private
  def clear_login_info_from_cookies
    cookies[:valleyer_id] = nil
    cookies[:valleyer_security_key] = nil
  end

end
